import serial
import time
import _thread  # 导入线程包
try:
  data_ser = serial.Serial("/dev/ttySpec",115200,timeout = 50)
  data_ser.flushInput()
except Exception as e:
  print("<Error> : ",e)
  exit()


def send_cmd():
  data_ser.write('m_float()\r\n'.encode("utf-8"))

def read_uart():
  # _thread.start_new_thread(get_data,()) # 开启线程，执行get_data方法
  send_cmd()
  time.sleep(2)
  res = data_ser.readline(data_ser.in_waiting).decode("utf-8")
  return res

def read_spec(retry=5):
  tmp = read_uart()
  while retry:
    decode_res=tmp.split(',')
    res_len=len(decode_res)
    retry-=1
    if res_len==17:
      tmp=tmp.strip()
      return tmp[0:-1]
    else:
      tmp = read_uart()
      print("retry:",retry)
  return "-1"

if __name__ == '__main__':
  rec=read_spec()
  print("res:",rec)
